<?php

namespace App\Extensions\Grid\Displayers;


use Encore\Admin\Grid;
use Encore\Admin\Grid\Column;

class FileModalActions extends \Encore\Admin\Grid\Displayers\Actions
{
    protected $actions = ['view', 'edit', 'delete'];
    protected $token = '';

    public function __construct($value, Grid $grid, Column $column, $row)
    {
        if (method_exists($row, 'token')) {
            $this->token = '?token=' . $row->token();
        }
        if (!$row->getIsImage() && !$row->getPreviewType()) {
            $this->disableView();
        }
        parent::__construct($value, $grid, $column, $row);
    }

    protected function renderView()
    {
        return <<<EOT
<a href="{$this->getResource()}/{$this->getRouteKey()}{$this->token}" class="modal-row-view" target="_blank">
    预览
</a>
EOT;
    }

    /**
     * Render edit action.
     *
     * @return string
     */
    protected function renderEdit()
    {
        return <<<EOT
<a href="{$this->getResource()}/{$this->getRouteKey()}/download{$this->token}" class="modal-row-download" target="_blank">
    下载
</a>
EOT;
    }

    /**
     * Render delete action.
     *
     * @return string
     */
    protected function renderDelete()
    {
        return <<<EOT
<a href="javascript:void(0);" data-id="{$this->getKey()}" class="modal-row-delete" data-href="{$this->getResource()}/{$this->getRouteKey()}">
    删除
</a>
EOT;
    }
}
